package com.cskaoyan.controller;

import com.cskaoyan.bean.BO.WxCommentCountBo;
import com.cskaoyan.bean.BO.WxCommentListBO;
import com.cskaoyan.bean.PO.MarketComment;
import com.cskaoyan.bean.VO.WxCommentCountVo;
import com.cskaoyan.bean.VO.WxCommentVO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.WxCommentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linhanxin
 * @date 2022/8/17.
 */
@RequestMapping("wx/comment")
@RestController
public class WxCommentController {
    @Autowired
    WxCommentService wxCommentService;

    //显示评论列表
    @RequestMapping("list")
    public BaseRespVo list(WxCommentListBO wxCommentListBO) {
        CommonData<WxCommentVO> data = wxCommentService.list(wxCommentListBO);
        return BaseRespVo.ok(data);
    }

    //统计有图评论和内容评论的数量
    @RequestMapping("count")
    public BaseRespVo count(WxCommentCountBo commentCountBo) {
        WxCommentCountVo wxCommentCountVo = wxCommentService.count(commentCountBo);
        return BaseRespVo.ok(wxCommentCountVo);
    }

    // 提交评论信息图片和内容
    @RequestMapping("post")
    public BaseRespVo post(@RequestBody MarketComment marketComment) {
        Session session = SecurityUtils.getSubject().getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        MarketComment commentVO = wxCommentService.post(marketComment,userId);
        if(commentVO!=null){
            return BaseRespVo.ok(0,commentVO,"成功");
        }else {
            return BaseRespVo.error(200,"参数错误");
        }
    }
}
